﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using CodeStash.Common.DTOS;
using CodeStash.Common.Encryption;

namespace RESTAPI_Test_Client
{
    internal class RESTAPILanguagesRunner : RESTAPIRunnerBase
    {

        internal override void RunSpecificRunnerAPILogic()
        {
            GetLanguagesUsingRegisteredEmailAndPassword();
        }


        private void GetLanguagesUsingRegisteredEmailAndPassword()
        {
            //REST controller Action is : GetAllLanguages(JSONCredentialInput input)
            //Encrypt using same rules as website, see App.Config, and CodeStash Web.Config
            values = new NameValueCollection();
            JSONCredentialInput input = new JSONCredentialInput(
                                "", //Encrypted using same rules as website
                                base.emailForWebsite, //Encrypted using same rules as website
                                base.passwordForWebsite); //Encrypted using same rules as website

            Utilities.AddValue(values, "input", input);
            Byte[] results = client.UploadValues("http://localhost:8300/Rest/GetAllLanguages", values);

            JSONLanguagesResult languages = Utilities.GetValue<JSONLanguagesResult>(results);
            if (languages.Languages.Any())
                Console.WriteLine(String.Format("Found {0} Languages", languages.Languages.Count()));
            else
                Console.WriteLine(languages.ErrorMessage);

        }


        

    }
}
